/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package init;

import Logic.Exit;
import Logic.MessageBox;
import Logic.This;
import inter.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 *
 * @author TuxCompany
 */
public class MainDesign extends javax.swing.JFrame {

    private boolean gradient;

    /**
     * Creates new form MainDesign
     */
    public MainDesign(GraphicsConfiguration gc, boolean gradient) {
        //super(gc);
        initComponents();
        MessageBox.show(this, "Welcome", "Bienvenido al Sistema", MessageBox.Informacion);
        LoadPost(gc, gradient);
        LoadInterno();
    }
    //<editor-fold defaultstate="collapsed" desc=" Funciones PostLoad ">
    /**
     * *****************
     * @Name= PostLoad *****************
     */
    //Notificador del Sistema
    private SystemTray tray;
    private TrayIcon trayIcon;

    private void InitTray() {
        if (SystemTray.isSupported()) {
            tray = SystemTray.getSystemTray();
            MouseListener mouseListener = new MouseListener() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    //System.exit(0);
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                }
            };
            trayIcon.setImageAutoSize(true);
            trayIcon.addMouseListener(mouseListener);
            try {
                tray.add(trayIcon);
                //trayIcon.displayMessage("Welcome", "Bienvenido", TrayIcon.MessageType.INFO);
            } catch (AWTException e) {
                System.err.println("No se pudo agregar el ícono a la barra tray");
            }
        }
    }

    //Post Carga a Efectos de Orden
    private void LoadPost(GraphicsConfiguration gc, boolean gradient) {
//        this.gradient = gradient;
//        jpTransparent.setOpaque(!gradient);
//        this.jToolBar1.setOpaque(!gradient);
//        if (!gradient) {
//            jpTransparent.setBackground(new Color(240, 240, 240, 128));
//        }
//        if (gc == null) {
//            this.cbxTransp.setSelected(false);
//        }
//       setLocationRelativeTo(null);
//        This.Maximized(this);
//        this.setResizable(false);
//        Image image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/resources/notify.png"));
//        trayIcon = new TrayIcon(image, "Software de Control Empresarial", null);
//        trayIcon.setToolTip("TuxNI Company");
//        InitTray();
//        //TuxNi Company = MHC + AxeStar
//        trayIcon.displayMessage("TuxNI Company", "Bienvenido al Sistema de Control Empresarial CE_MANI", TrayIcon.MessageType.INFO);
    }

    private void LoadInterno() {
        This.AddInter(PaneInterno, CP);
        This.AddInter(PaneInterno, CU);
        This.AddInter(PaneInterno, CPV);
        This.AddInter(PaneInterno, CMP);
        This.AddInter(PaneInterno, CC);
        This.AddInter(PaneInterno, CTC);
    }

    /**
     * ***************** ***************** ***************** *****************
     */
    //</editor-fold>
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar2 = new javax.swing.JToolBar();
        cbxTransp = new javax.swing.JCheckBox();
        jToolBar1 = new javax.swing.JToolBar();
        lblExit = new javax.swing.JLabel();
        lblUser = new javax.swing.JLabel();
        lblProducto = new javax.swing.JLabel();
        lblProveedor = new javax.swing.JLabel();
        lblCliente = new javax.swing.JLabel();
        lblMaterPrima = new javax.swing.JLabel();
        jpTransparent = new javax.swing.JPanel() {
            protected void paintComponent(Graphics g) {
                if (g instanceof Graphics2D && gradient) {
                    final int R = 240;
                    final int G = 240;
                    final int B = 240;

                    Paint p =
                    new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0),
                        getWidth(), getHeight(), new Color(R, G, B, 255), true);
                    Graphics2D g2d = (Graphics2D)g;
                    g2d.setPaint(p);
                    g2d.fillRect(0, 0, getWidth(), getHeight());
                } else {
                    super.paintComponent(g);
                }
            }
        }
        ;
        PaneInterno = new javax.swing.JDesktopPane();
        lblStatus = new javax.swing.JLabel();
        jToolBar3 = new javax.swing.JToolBar();
        lblCompra = new javax.swing.JLabel();

        jToolBar2.setFloatable(false);

        cbxTransp.setSelected(true);
        cbxTransp.setText("Transparencia");
        cbxTransp.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        cbxTransp.setFocusable(false);
        cbxTransp.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        cbxTransp.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cbxTransp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbxTranspActionPerformed(evt);
            }
        });
        jToolBar2.add(cbxTransp);

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Sistema de Control Empresarial de MANI");
        setAlwaysOnTop(true);
        setIconImage( This.getIconImageFrame());
        setUndecorated(true);

        jToolBar1.setFloatable(false);
        jToolBar1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jToolBar1.setRollover(true);
        jToolBar1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        lblExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/boot.png"))); // NOI18N
        lblExit.setToolTipText("Salir del Sistema");
        lblExit.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblExit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblExitMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                MouseExit1(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                MouseIntro1(evt);
            }
        });
        jToolBar1.add(lblExit);

        lblUser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/session.png"))); // NOI18N
        lblUser.setToolTipText("Control de Usuarios");
        lblUser.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblUser.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblUserMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                MouseExit2(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                MouseIntro2(evt);
            }
        });
        jToolBar1.add(lblUser);

        lblProducto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/bum.png"))); // NOI18N
        lblProducto.setToolTipText("Catalogo Productos");
        lblProducto.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblProducto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblProductoMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                MouseExit3(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                MouseIntro3(evt);
            }
        });
        jToolBar1.add(lblProducto);

        lblProveedor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/resource-group-new.png"))); // NOI18N
        lblProveedor.setToolTipText("Catalogo de Proveedores");
        lblProveedor.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblProveedor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblProveedorMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                MouseExit4(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                MouseEnter4(evt);
            }
        });
        jToolBar1.add(lblProveedor);

        lblCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/user-group-new.png"))); // NOI18N
        lblCliente.setToolTipText("Catalogo de Clientes");
        lblCliente.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblCliente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblClienteMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                MouseExit5(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                MouseEnter5(evt);
            }
        });
        jToolBar1.add(lblCliente);

        lblMaterPrima.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/emblem-package.png"))); // NOI18N
        lblMaterPrima.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblMaterPrima.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblMaterPrimaMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                MouseExit6(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                MouseEnter6(evt);
            }
        });
        jToolBar1.add(lblMaterPrima);

        jpTransparent.setLayout(new java.awt.BorderLayout());

        PaneInterno.setOpaque(false);
        jpTransparent.add(PaneInterno, java.awt.BorderLayout.CENTER);

        lblStatus.setFont(new java.awt.Font("Century Schoolbook L", 0, 16)); // NOI18N
        lblStatus.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jpTransparent.add(lblStatus, java.awt.BorderLayout.PAGE_START);

        jToolBar3.setFloatable(false);
        jToolBar3.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jToolBar3.setRollover(true);

        lblCompra.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/insert-object.png"))); // NOI18N
        lblCompra.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblCompra.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblCompraMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                MouseExit7(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                MouseEnter7(evt);
            }
        });
        jToolBar3.add(lblCompra);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpTransparent, javax.swing.GroupLayout.DEFAULT_SIZE, 1077, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpTransparent, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 730, Short.MAX_VALUE)
            .addComponent(jToolBar3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </editor-fold>//GEN-END:initComponents

    private void lblExitMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblExitMouseClicked
        // TODO add your handling code here:
        Exit.Ok();
    }//GEN-LAST:event_lblExitMouseClicked

    private void MouseIntro1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseIntro1
        // TODO add your handling code here:
        lblExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/boot2.png"))); // NOI18N
    }//GEN-LAST:event_MouseIntro1

    private void MouseExit1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseExit1
        // TODO add your handling code here:
        lblExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/boot.png"))); // NOI18N
    }//GEN-LAST:event_MouseExit1

    private void MouseIntro2(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseIntro2
        // TODO add your handling code here:
        lblUser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/session2.png"))); // NOI18N
    }//GEN-LAST:event_MouseIntro2

    private void MouseExit2(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseExit2
        // TODO add your handling code here:
        lblUser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/session.png"))); // NOI18N
    }//GEN-LAST:event_MouseExit2

    private void lblUserMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblUserMouseClicked
        // TODO add your handling code here:
        This.show(CU);
    }//GEN-LAST:event_lblUserMouseClicked

    private void cbxTranspActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxTranspActionPerformed
        // TODO add your handling code here:
        if (cbxTransp.isSelected()) {
            new Init_Window().LoadMainDesign();
            this.dispose();
        } else {
            new MainDesign(null, true).setVisible(true);
            this.dispose();
        }
        tray.remove(trayIcon);
    }//GEN-LAST:event_cbxTranspActionPerformed

    private void MouseIntro3(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseIntro3
        // TODO add your handling code here:
        lblProducto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/bum2.png"))); // NOI18N
        lblStatus.setText("Catalogo Productos");
    }//GEN-LAST:event_MouseIntro3

    private void MouseExit3(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseExit3
        // TODO add your handling code here:
        lblProducto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/bum.png"))); // NOI18N
        lblStatus.setText("");
    }//GEN-LAST:event_MouseExit3

    private void lblProductoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblProductoMouseClicked
        // TODO add your handling code here:
        This.show(CP);
    }//GEN-LAST:event_lblProductoMouseClicked

    private void lblProveedorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblProveedorMouseClicked
        // TODO add your handling code here:
        This.show(CPV);
    }//GEN-LAST:event_lblProveedorMouseClicked

    private void MouseEnter4(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseEnter4
        // TODO add your handling code here:
        lblStatus.setText("Catalogo de Proveedores");
    }//GEN-LAST:event_MouseEnter4

    private void MouseExit4(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseExit4
        // TODO add your handling code here:
        lblStatus.setText("");
    }//GEN-LAST:event_MouseExit4

    private void lblClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblClienteMouseClicked
        // TODO add your handling code here:
        This.show(CC);
    }//GEN-LAST:event_lblClienteMouseClicked

    private void MouseEnter5(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseEnter5
        // TODO add your handling code here:
        lblStatus.setText("Catalogo de Clientes");
    }//GEN-LAST:event_MouseEnter5

    private void MouseExit5(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseExit5
        // TODO add your handling code here:
        lblStatus.setText("");
    }//GEN-LAST:event_MouseExit5

    private void lblMaterPrimaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblMaterPrimaMouseClicked
        // TODO add your handling code here:

        if (!CMP.isVisible() || CMP.isIcon()) {
            CMP.LoadProveedor();
            CMP.LoadProducto();
        }
        if (CMP.Status == 0 && CMP.Status2 == 0) {
            This.show(CMP);
        }

    }//GEN-LAST:event_lblMaterPrimaMouseClicked

    private void MouseEnter6(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseEnter6
        // TODO add your handling code here:
        lblStatus.setText("Catalogo de Materia Prima");
    }//GEN-LAST:event_MouseEnter6

    private void MouseExit6(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseExit6
        // TODO add your handling code here:
        lblStatus.setText("");
    }//GEN-LAST:event_MouseExit6

    private void lblCompraMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblCompraMouseClicked
        // TODO add your handling code here:
        if (!CTC.isVisible() || CTC.isIcon()) {
            CTC.LoadProveedor();
        }
        if (CTC.Status == 0) {
            This.show(CTC);
        }
    }//GEN-LAST:event_lblCompraMouseClicked

    private void MouseEnter7(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseEnter7
        // TODO add your handling code here:
        lblStatus.setText("Control de Compras de Materia Prima");
    }//GEN-LAST:event_MouseEnter7

    private void MouseExit7(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseExit7
        // TODO add your handling code here:
        lblStatus.setText("");
    }//GEN-LAST:event_MouseExit7

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainDesign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainDesign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainDesign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainDesign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                // new MainDesign().setVisible(true);
            }
        });
    }
    //<editor-fold defaultstate="collapsed" desc=" Control de Frames Internos ">
    //Control de Frames Internos
    ControlUser CU = new ControlUser();
    CtrProducto CP = new CtrProducto();
    CtrProveedor CPV = new CtrProveedor();
    CtrMPrima CMP = new CtrMPrima();
    CtrCliente CC = new CtrCliente();
    CtrCompra CTC = new CtrCompra();
    //</editor-fold>
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane PaneInterno;
    private javax.swing.JCheckBox cbxTransp;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JPanel jpTransparent;
    private javax.swing.JLabel lblCliente;
    private javax.swing.JLabel lblCompra;
    private javax.swing.JLabel lblExit;
    private javax.swing.JLabel lblMaterPrima;
    private javax.swing.JLabel lblProducto;
    private javax.swing.JLabel lblProveedor;
    private javax.swing.JLabel lblStatus;
    private javax.swing.JLabel lblUser;
    // End of variables declaration//GEN-END:variables
}
